var consoleFn = {
		data:{},
		/**
		 * @desc 初始化控制菜单
		 * @param _menus
		 */
		initLeftMenu:function(_menus){
			var _this = this;
			var htmlPanel = [];
			$("#easyui-accordion").empty();
			$.each(_menus.menus, function(i, n){
				htmlPanel.push('<div data-options="iconCls:\''+ (n.iconCls || 'tree-file')  +'\'"  title="&nbsp;'+ (n.text || n.menuName) +'" style="padding:10px;">');
				htmlPanel.push('<ul id="tree_'+ n.id +'"></ul>');
				$("#easyui-accordion").append( htmlPanel.join(''));
				htmlPanel = [];
				setTimeout(function(){
					$('#tree_'+n.id).tree({
						data : n.children,
						formatter:function(node){
							return node.text || node.menuName;
						},
						onClick: function(node){
							if(node.children && node.children.length>0) return;
							if(node.menuUrl){ _this.addTab(node.text || node.menuName,node.id, node.menuUrl,node.iconCls);}
							else{ alert("don't config menuUrl ..."); }
						}
					});
				},0);
		    });
			$('#easyui-accordion').accordion({  animate:false });  
			
			/*添加页签关闭事件*/
			$('#easyui-tabs').tabs({
			    border:false,    
			    onSelect:function(title){
			    	/*var curTab = $(this).tabs('getSelected');
			    	var curTabWin = curTab.find('iframe')[0].contentWindow;
			    	if(curTabWin && curTabWin.$){
			    		console.log('重载');
			    		curTabWin.$('body .easyui-layout').layout('resize', { width:'100%' });
			    		curTabWin.$('#toolbar').css({width:'100%'});
			    	}*/
			    	return false;
			    }
			});  
		},
		/**
		 * @param index
		 * 关闭页签
		 */
		closeTab:function(index){
			var tabId = null;
			if(index==undefined || index==null){
				var tab = $('#easyui-tabs').tabs('getSelected');
				index = $('#easyui-tabs').tabs('getTabIndex',tab);
				tabId = tab.panel('options').id;
			}else{
				var tab = $('#easyui-tabs').tabs('getTab',index);
				tabId = tab.panel('options').id;
			}
			/*关闭自己,并选择父tab*/
			var pTabId = tabId.split("-")[0];
			var ptab = $("#easyui-tabs").tabs("getTabById",pTabId);
			if(ptab){
				var pindex = $('#easyui-tabs').tabs('getTabIndex',ptab);
				$('#easyui-tabs').tabs('select',pindex);
			}
			
			$('#easyui-tabs').tabs("close",index);
			return tabId;
		},
		/**
		 * @param index
		 * 关闭页签并刷新父窗口grid
		 */
		closeTabAndFrushGrid:function(index){
			var _this = this;
			var tabId = _this.closeTab(index);
			var pTabId = tabId.split("-")[0];
			var ptab = $("#easyui-tabs").tabs("getTabById",pTabId);
			var iframeWindow=ptab.find('iframe')[0].contentWindow;
			iframeWindow.$('#dataGrid').datagrid("reload");
		},
		getTabData:function(){
			var tab = $('#easyui-tabs').tabs('getSelected');
			var index = $('#easyui-tabs').tabs('getTabIndex',tab);
			var tabId = tab.panel('options').id;
			return this.data[tabId] || null;
		},
		/**
		 * @desc 新增页签
		 * @param menuName
		 * @param menuId
		 * @param url
		 * @returns
		 */
		addTab:function(menuName,menuId,url,iconCls,data){
			this.data[menuId] = data;
			var easyuiTabs = $('#easyui-tabs').tabs({});
			if(easyuiTabs.tabs('exists', menuName)){
				easyuiTabs.tabs('select',menuName);
			}else{
				/*父页面索引*/
				var ptab = $('#easyui-tabs').tabs('getSelected');
				var pIndex = $('#easyui-tabs').tabs('getTabIndex',ptab);
				
				var url = url || '' ; 
				if(url=='') return alert('no url addr ');
				
				if(url.indexOf('?')>-1){ url += ('&menuId='+menuId + '&r='+ Math.random() );}
				else{ url += ('?menuId='+ menuId + '&r='+ Math.random() ); }
				
				url += ('&pIndex='+pIndex) ;
				var tabId = menuId; 

				easyuiTabs.tabs('add',{
					iconCls: iconCls || '',
					id: tabId,
				    title: menuName,
				    content:(function(url){
						var prefix = CP;
						if(/^(\\\\|ftp|http:\/\/)/ig.test(url)) prefix = "";
						if(prefix == '/') prefix = "";
						prefix += url;
						return '<iframe scrolling="auto" frameborder="0"  src="'+ prefix +'" style="width:100%;height:100%;" ></iframe>';
					})(url),
				    closable:true
				});
			}
			return menuId;
		}
};